package test.performance;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.spoofax.jsglr.InvalidParseTableException;
import org.spoofax.jsglr.ParseTableManager;
import org.spoofax.jsglr.SGLR;

import aterm.ATerm;

public class MemoryExpander implements Runnable {

	@Override
	public void run() {
		ParseTableManager ptm = new ParseTableManager();
		SGLR sglr =null;
		long iMaxMem;
		long iTotMem;
		long iFreeMem =0;
		long initTime;
		long endTime;
		long fMaxMem;
		long fTotMem;
		long fFreeMem = 0;
		try {
			sglr = new SGLR(ptm.getFactory(),
					ptm.loadFromFile("include/aspectj-abc.tbl"));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidParseTableException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
		System.gc();
		iMaxMem = Runtime.getRuntime().maxMemory();
		iTotMem = Runtime.getRuntime().totalMemory();
		iFreeMem = Runtime.getRuntime().freeMemory();
		initTime = System.currentTimeMillis();
		
		ATerm t = sglr.parse(new FileInputStream(new File("input/AcceptedTests/ATest11.aj")));
	
		endTime = System.currentTimeMillis();
		fMaxMem = Runtime.getRuntime().maxMemory();
		fTotMem = Runtime.getRuntime().totalMemory();
		fFreeMem = Runtime.getRuntime().freeMemory();
		} catch(Exception e){
			e.printStackTrace();
		}
		
		System.out.println("Memory Expander result:" + (iFreeMem-fFreeMem));

	}

}